package com.bazaaroid.client.web.gwt.partnermodule.client.view.partnerinfo;

import com.bazaaroid.client.web.gwt.partnermodule.client.dto.PartnerContactDTO;
import com.bazaaroid.client.web.gwt.partnermodule.client.view.common.TitleCommandBar;
import com.bazaaroid.client.web.gwt.partnermodule.client.view.partnerinfo.impl.PartnerInfoTabViewImpl;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PartnerContactEntryView extends PartnerGenericEntryView<PartnerContactDTO> {

	private TitleCommandBar titleBar;
	private HTML telephone = new HTML();
	private HTML mobile = new HTML();
	private HTML fax = new HTML();
	private HTML email = new HTML();
	private HTML site = new HTML();
	
	public class EditClickHandler implements ClickHandler {
		@Override
		public void onClick(ClickEvent event) {
			getPartnerInfoTabView().startEditPartnerContact(PartnerContactEntryView.this);
		}
	}
	
	public class DeleteClickHandler implements ClickHandler {
		@Override
		public void onClick(ClickEvent event) {
			if(Window.confirm("Are you sure you wand to delete contact information?")) {
				getPartnerInfoTabView().getPartnerContactViewHandler().onPartnerGenericEntryDeleted(getPartnerGenericDTO());
				removeFromParent();
			}
		}
	}
	
	public PartnerContactEntryView(PartnerInfoTabViewImpl partnerInfoTabView, PartnerContactDTO partnerContactDTO) {
		super(partnerInfoTabView, partnerContactDTO);
		
		VerticalPanel partnerContactViewPanel = new VerticalPanel();
		initWidget(partnerContactViewPanel);
		
		titleBar = new TitleCommandBar("Contact");
		titleBar.addCommand("edit", new EditClickHandler());
		titleBar.addCommand("delete", new DeleteClickHandler());
		partnerContactViewPanel.add(titleBar);
		partnerContactViewPanel.add(telephone);
		partnerContactViewPanel.add(mobile);
		partnerContactViewPanel.add(fax);
		partnerContactViewPanel.add(email);
		partnerContactViewPanel.add(site);
				partnerContactViewPanel.setStyleName("partnerInfoPanel");
		telephone.setStyleName("partnerInfoDescription");
		mobile.setStyleName("partnerInfoDescription");
		//titleBar.addStyleName("");
		update();
	}
	
	public void update() {
		telephone.setHTML("<b>Telephone: </b>" + getPartnerGenericDTO().getTelephone());
		mobile.setHTML("<b>Mobile: </b>" + getPartnerGenericDTO().getMobile());
		fax.setHTML("<b>Fax: </b>" + getPartnerGenericDTO().getFax());
		email.setHTML("<b>Email: </b>" + getPartnerGenericDTO().getEmail());
		site.setHTML("<b>Site: </b> <a href='" + getPartnerGenericDTO().getSite() + "'>" + getPartnerGenericDTO().getSite() + "</a>");
	}

}
